//
//  EaseIMManager.m
//  EaseIMTest
//
//  Created by yshow on 16/8/25.
//  Copyright © 2016年 yshow. All rights reserved.
//

#import "EaseIMManager.h"

@implementation EaseIMManager
+(void)regisEaseIM
{
    //AppKey:注册的AppKey，详细见下面注释。
    //apnsCertName:推送证书名（不需要加后缀），详细见下面注释。
    EMOptions *options = [EMOptions optionsWithAppkey:EaseAppKey];
    options.apnsCertName = EaseAPNSName;
    //输出日志 默认EMLogLevelDebug
    options.logLevel = EMLogLevelDebug;
    //设置自动登录 默认yes
    options.isAutoLogin = YES;
    [[EMClient sharedClient] initializeSDKWithOptions:options];
}

+(void)userLoginEaseIMWithUserId:(NSString *)userId password:(NSString *)password
{
    EMError *error = [[EMClient sharedClient] loginWithUsername:userId password:password];
    if (!error) {
        NSLog(@"环信服务器登录成功");
        //获取本地会话列表数据
        [[EMClient sharedClient].chatManager loadAllConversationsFromDB];
    }
}

+(void)userResgisEaseIMWithUserId:(NSString *)userId password:(NSString *)password
{
    EMError *error = [[EMClient sharedClient] registerWithUsername:userId password:password];
    if (error==nil) {
        NSLog(@"注册成功");
        //注册成功后自行登陆环信服务器
        [self userLoginEaseIMWithUserId:userId password:password];
    }
}

@end
